import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import * as path from 'path'

// 自动按需载入 element-plus
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

export default defineConfig({
  server: {
    proxy: {
      '/pubg_api': {
        target: 'https://api.pubg.com/',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/pubg_api/, '')
      },
      '/nodeApi': {
        target: 'http://localhost:3000/',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/nodeApi/, '')
      },
      '/baseApi': {
        target: 'http://localhost:3337/',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/baseApi/, '')
      }
    },
    port: 8081
  },
  resolve: {
    alias: { // 这里就是需要配置resolve里的别名
      '@': path.join(__dirname, 'src') // path记得引入
      // 'vue': 'vue/dist/vue.esm-bundler.js' // 定义vue的别名，如果使用其他的插件，可能会用到别名
    }
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })]
})
